package main

import (
	"fmt"
	"gitee.com/yangguoliang001/go-gin-vue3/common"
	"gitee.com/yangguoliang001/go-gin-vue3/config"
	_ "gitee.com/yangguoliang001/go-gin-vue3/docs" // 需要导入docs
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/logger"
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/timeutil"
	router "gitee.com/yangguoliang001/go-gin-vue3/routes"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

// 49.232.205.166:9988 服务器地址
// 如果是本地运行需要修改 @host 为 localhost:9988
// 然后运行 swag init 重新生成 swagger

// @title swagger 接口文档
// @version 2.0
// @description
// @host      49.232.205.166:9988
// @BasePath /
// @securityDefinitions.apikey  LoginToken
// @in                          header
// @name                        Authorization
func main() {
	// 初始化配置
	common.InitConfig()
	// 初始化日志
	accessLogger, err := logger.NewJSONLogger(
		logger.WithDisableConsole(),
		logger.WithField("domain", fmt.Sprintf("%s[%s]", config.ProjectName, "dev")),
		logger.WithTimeLayout(timeutil.CSTLayout),
		logger.WithFieldP(config.ProjectAccessLogFile),
	)

	if err != nil {
		panic(err)
	}
	//
	defer func() {
		_ = accessLogger.Sync()
	}()

	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()
	r, _ = router.CollectRoute(r, accessLogger)
	port := viper.GetString("server.port")
	fmt.Println("server is running: " + port)
	if port != "" {
		panic(r.Run(":" + port))
	}
	panic(r.Run())
}
